package com.gec.system.controller;


import com.gec.system.service.SysMenuService;
import com.gec.system.system.SysMenu;
import com.gec.system.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/system/menu")
public class SysMenuController {
    @Autowired
    SysMenuService service;

    @ApiOperation("查看菜单")
    @GetMapping("findNode")
    public Result findNode(){
        List<SysMenu> menus = service.findNode();
        return Result.ok(menus);
    }
    @ApiOperation("添加菜单")
    @PostMapping("/addMenu")
    public Result addMenu(@RequestBody SysMenu sysMenu){
        this.service.save(sysMenu);
        return Result.ok();
    }
    @ApiOperation("删除菜单")
    @DeleteMapping("delete/{id}")
    public Result removeMenuById(@PathVariable Long id){
        boolean i = service.removeMenuById(id);
        return i?Result.ok():Result.fail();

    }

    @ApiOperation("修改菜单")
    @PostMapping("updateMenu")
    public Result updateMenu(@RequestBody SysMenu menu){
        boolean i = service.updateById(menu);
        return i?Result.ok():Result.fail();
    }
    @ApiOperation("更新状态")
    @PostMapping("/updateStatus")
    public Result updateStatus(@RequestBody SysMenu menu){
        boolean isOK = this.service.updateStauts(menu);
        return isOK?Result.ok():Result.fail();
    }

}
